home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / dodge.swf / scripts / __Packages / MovingEnemy.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  2.5 KB  |  100 lines

  1. class MovingEnemy extends Enemy
  2. {
  3.    var targetCoords;
  4.    var mc;
  5.    var tm;
  6.    static var SCORE = 150;
  7.    static var SPEED = 2;
  8.    static var ACCEL = 0.30000000000000004;
  9.    static var WAIT_TIME = 60;
  10.    static var ENEMY_TYPE = "enemy2";
  11.    static var MAX_HEALTH = 3;
  12.    static var SHAPE_FLAG = false;
  13.    static var COLOR = 65535;
  14.    var xspeed = 0;
  15.    var yspeed = 0;
  16.    var skipSwitch = 0;
  17.    function MovingEnemy(x, y)
  18.    {
  19.       super(x,y);
  20.    }
  21.    function getScore()
  22.    {
  23.       return MovingEnemy.SCORE;
  24.    }
  25.    function getSpeed()
  26.    {
  27.       return MovingEnemy.SPEED;
  28.    }
  29.    function getEnemyType()
  30.    {
  31.       return MovingEnemy.ENEMY_TYPE;
  32.    }
  33.    function getWaitTime()
  34.    {
  35.       return MovingEnemy.WAIT_TIME;
  36.    }
  37.    function getMaxHealth()
  38.    {
  39.       return MovingEnemy.MAX_HEALTH;
  40.    }
  41.    function getAccel()
  42.    {
  43.       return MovingEnemy.ACCEL;
  44.    }
  45.    function getColor()
  46.    {
  47.       return MovingEnemy.COLOR;
  48.    }
  49.    function getShapeFlag()
  50.    {
  51.       return MovingEnemy.SHAPE_FLAG;
  52.    }
  53.    function move()
  54.    {
  55.       if(this.skipSwitch % 3 == 0)
  56.       {
  57.          var _loc4_ = undefined;
  58.          _loc4_ = Math.atan2(this.targetCoords.y - this.mc._y,this.targetCoords.x - this.mc._x);
  59.          var _loc2_ = this.xspeed * this.xspeed + this.yspeed * this.yspeed;
  60.          var _loc3_ = this.getSpeed() * this.getSpeed();
  61.          this.xspeed += this.getAccel() * Math.cos(_loc4_);
  62.          this.yspeed += this.getAccel() * Math.sin(_loc4_);
  63.          if(_loc2_ > _loc3_)
  64.          {
  65.             this.xspeed *= _loc3_ / _loc2_;
  66.             this.yspeed *= _loc3_ / _loc2_;
  67.          }
  68.          this.mc._rotation = CustomMath.radToDeg(Math.atan2(this.yspeed,this.xspeed));
  69.       }
  70.       this.skipSwitch = this.skipSwitch + 1;
  71.       this.mc._x += this.xspeed;
  72.       this.mc._y += this.yspeed;
  73.       this.tm.makeTrail();
  74.    }
  75.    function step()
  76.    {
  77.       if(this.checkProximity())
  78.       {
  79.          this.assignNewTarget();
  80.       }
  81.       else
  82.       {
  83.          this.move();
  84.       }
  85.       this.shootIfAble();
  86.       this.checkHit();
  87.    }
  88.    function getWeaponsPoints()
  89.    {
  90.       var _loc2_ = new flash.geom.Point(this.mc.turret.weapon1._x,this.mc.turret.weapon1._y);
  91.       this.mc.turret.localToGlobal(_loc2_);
  92.       return new Array(_loc2_);
  93.    }
  94.    function rotateToPlayer()
  95.    {
  96.       var _loc3_ = Math.atan2(_root.player.getMovie()._y - this.mc._y,_root.player.getMovie()._x - this.mc._x);
  97.       this.mc.turret._rotation = CustomMath.radToDeg(_loc3_) - this.mc._rotation;
  98.    }
  99. }
  100.